#ifndef __BLEWIFI_H
#define __BLEWIFI_H

#include "tools.h"
//#include "encryptionSM4.h"

////////////// 引脚 ////////////////
// 复位引脚
#define BW_RTC              RCM_APB2_PERIPH_GPIOD 
#define BW_PinPort          GPIOD 
#define BW_PinId            GPIO_PIN_3  

#define BW_SET()            BW_PinPort -> BSC = BW_PinId 
#define BW_RESET()          BW_PinPort -> BC  = BW_PinId 


////////////// 常量：///////////////
//热点信息
#define  Wifi_Name                   Chgr_Name             // 热点名称;
#define  Wifi_Name_size              8
#define  Wifi_PWD                    "12345678"            // 热点密码;
#define  Wifi_PWD_size               8
#define  wifi_AP_connMax             "5"                   // 热点最大连接数;
#define  wifi_AP_connMax_size        1
//待连接ap信息
#define  wifi_connect_name_def       "TmallRouter_3E40"
#define  wifi_connect_name_def_len   16
#define  wifi_connect_pwd            ""
#define  wifi_connect_pwd_size       0


//http请求
#define  Req_HTTP                       "1"
#define  Req_HTTPs                      "2" 
//请求Method
#define  Req_Method_Get                 "2"
#define  Req_Method_Post                "3"
//请求类型
#define  Req_Type_keyValuePair          "application/x-www-form-urlencoded"             //键值对数据
#define  Req_Type_keyValuePair_size     33
#define  Req_Type_Json                  "application/json"                              //json格式
#define  Req_Type_Json_size             16
#define  Req_Type_FormData              "multipart/form-data"                           //表单数据
#define  Req_Type_FormData_size         19
#define  Req_Type_XML                   "text/xml"                                      //xml数据
#define  Req_Type_XML_size              8
#define  Req_Type_Text                  "text/html"                                     //text文本数据
#define  Req_Type_Text_size             9

//请求主机
#define  Req_host                       "evse.natapp1..cc"                               //内网穿透主机
#define  Req_host_size                  16 
//#define  Req_host                    192.168.1.100                                 //局域网主机
//#define  Req_host_size               13 

//请求端口号
#define  Req_port                    "80"
#define  Req_port_size               2

//请求路径
#define  Req_path                    "/api/ChargingInfo/add"
#define  Req_path_size               21

//json选项：
#define  json_key1                   "deviceId"
#define  json_value1                 Chgr_Name

//json 字符串
#define  Req_json                    {json_key1: json_value1 \
                                     }

																		 
///////////// 指令集 //////////////			
// 蓝牙模式设置																		 
#define	 bleWifi_Cmd_NameSet             "AT+BLENAME=EVSE"
#define  bleWifi_Cmd_NameSet_size        15																		 
#define	 bleWifi_Cmd_ModeSet             "AT+BLEMODE=0"
#define  bleWifi_Cmd_ModeSet_size        12	
// WiFi模式设置																		 
#define	 bleWifi_Cmd_WifiModeSet         "AT+WMODE=3,1"
#define  bleWifi_Cmd_WifiModeSet_size    12		 
#define	 bleWifi_Cmd_APSet  						 "AT+WAP=EVSE"         //Wifi_Name,Wifi_PWD,1,wifi_AP_connMax,1 
#define	 bleWifi_Cmd_APSet_size          11 																		 
#define  bleWifi_Cmd_AutoConnect    		 "AT+WAUTOCONN=1"
#define  bleWifi_Cmd_AutoConnect_size		 14																		 
// wifi连接																		 
#define  bleWifi_Cmd_Connect             "AT+WJAP="        //wifi_connect_name,wifi_connect_pwd
#define  bleWifi_Cmd_Connect_size        8 																		 
// 连接服务器指令
#define	 bleWifi_Cmd_httpReq             "AT+HTTTPCLIENTLINE="
#define	 bleWifi_Cmd_httpReq_size        19	
// 连接请求参数
#define  Req_Protocol                    Req_HTTP
#define	 Req_method                      Req_Method_Post 
#define	 Req_Type                        Req_Type_keyValuePair
#define	 Req_Type_size                   Req_Type_keyValuePair_size

// 查询指令
#define	 bleWifi_Cmd_bleMacAddr          "AT+BLEMAC?"           //查询ble地址
#define  bleWifi_Cmd_bleMacAddr_size     10
#define	 bleWifi_Cmd_wifiSSI             "AT+WRSSI?"            //查询WiFi信号强度
#define  bleWifi_Cmd_wifiSSI_size        9 
// 查询ble状态
#define  bleWifi_Cmd_bleModeQuery        "AT+BLEMODE?" 
#define  bleWifi_Cmd_bleModeQuery_size   11
//  查询wifi状态
#define  bleWifi_Cmd_wifiModeQuery       "AT+WMODE?" 
#define  bleWifi_Cmd_wifiModeQuery_size  9
// 查询wifi国家码
#define  bleWifi_Cmd_cntryQuery          "AT+WCOUNTRY?" 
#define  bleWifi_Cmd_cntryQuery_size     12


// 查询回复字符串关键字：
#define  bleWifi_reply_checkBleMode              "+BLEMODE"
#define  bleWifi_reply_checkBleMode_size         8
#define  bleWifi_reply_checkWifiMode             "+WMODE"
#define  bleWifi_reply_checkWifiMode_size        6
#define  bleWifi_reply_checkBleAddr              "+BLEMAC"
#define  bleWifi_reply_checkBleAddr_size         7
#define  bleWifi_reply_checkSSI                  "+WRSSI"
#define  bleWifi_reply_checkSSI_size             6



// 查询id
enum blewifi_check_id{
	  bleWifi_check_bleAddr = 1,           //读取蓝牙地址
	  bleWifi_check_SSI,                   //读取信号强度
	  bleWifi_check_bleMode,               //读取Ble模式
	  bleWifi_check_wifiMode,              //读取wifi模式
	  bleWifi_check_country,               //度国家码	  
};
// 设置id
enum blewifi_set_id{
	  bleWifi_set_bleName = 1,           //设置蓝牙名称
	  bleWifi_set_bleMode,               //设置蓝牙模式	    
	  bleWifi_set_ap,                    //设置wifi的ap热点
	  bleWifi_set_autoConn,              //设置自动连接
	  bleWifi_set_wifiMode,              //设置wifi模式	
};
// 重置最大步骤：
#define  bw_reset_max                  19


																		 
//////////// 串口 //////////////
#if BleWifi_Uart_Using == BleWifi_Uart1
	#define  bleWifi_Uart                    UART1_Id 
	#if uart_DMA_send > 0																		 
		#define  bleWifi_DMA_Chn		           UART1_DMA_Channel		    
		#define  bleWifi_DMA_flg_TC						 UART1_DMA_FLAG_TC 			  									 
	#endif
	#define  bleWifi_BUFFER                  uart1Ctrl.uartTxDatas
#elif BleWifi_Uart_Using == BleWifi_Uart5
  #define  bleWifi_Uart                    UART5_Id 
	#if uart_DMA_send > 0																		 
		#define  bleWifi_DMA_Chn		           UART5_DMA_Channel		    
		#define  bleWifi_DMA_flg_TC						 UART5_DMA_FLAG_TC 			  									 
	#endif
	#define  bleWifi_BUFFER                  uart5Ctrl.uartTxDatas
#endif																 

///////////// 函数声明 //////////////
void ledWifi_init_output(void);
void ledWifi_init_input(void);
uint8_t rst_get_level(void);
void bleWifi_restart(void);
void ble_set(uint8_t setId);
void wifi_set(uint8_t setId);
void wifi_conn(void);
void blewifi_check(uint8_t checkId);
void blewifi_httpReq(void);

#endif

